var studentAttendenceChartFirstTen = echarts.init(document.getElementById('studentAttendenceChartFirstTen'));
var studentAttendenceChartEndTen = echarts.init(document.getElementById('studentAttendenceChartEndTen'));
option2 = {
    title: {
            text: '到课率排行',
        subtext: '前十名'
    },
    tooltip: {
    },
    legend: {
        data:['班级']
    },
    toolbox: {
    },
    xAxis:  {
        type: 'category',
        data: ['','','','','','','','','','',''],
        axisLabel: {
            interval:0,
            rotate:40
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} %'
        }
    },
    series: [
        {
            name:'到课率',
            type:'bar',
            data:[100,100,100,100,100,100,100,100,100,100],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }
    ]
};
option = {
    title: {
        text: '课率排行',
        subtext: '后十名'
    },
    tooltip: {
    },
    legend: {
        data:['班级']
    },
    toolbox: {
    },
    xAxis:  {
        type: 'category',
        data: ['','','','','','','','','','',''],
        axisLabel: {
            interval:0,
            rotate:40
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} %'
        }
    },
    series: [
        {
            name:'到课率',
            type:'bar',
            data:[100,100,100,100,100,100,100,100,100,100],
            markPoint: {
                data: [
                    {type: 'max', name: '最大值'},
                    {type: 'min', name: '最小值'}
                ]
            },
            markLine: {
                data: [
                    {type: 'average', name: '平均值'}
                ]
            }
        }
    ]
};
$(function () {
    // var setting = {
    //     data: {
    //         simpleData: {
    //             enable: true,
    //             idKey: "menuId",
    //             pIdKey: "parentId",
    //             rootPId: -1
    //         },
    //         key: {
    //             url: "nourl"
    //         }
    //     },
    //     check: {
    //         enable: true,
    //         nocheckInherit: true
    //     }
    // };
    // var ztree;
    // $.get(baseURL + "sys/menu/list", function(r){
    //     ztree = $.fn.zTree.init($("#ztree"), setting, r);
    //     //展开所有节点
    //     ztree.expandAll(false);
    // });
    $.ajax({
        url: baseURL + "/college/getAllStudentCollege",
        data: {},
        success: function (r) {
            $("#College").append("<option value=''>全校</option>");
            for (i = 0; i < r.list.length; i++) {
                var tname = r.list[i].collegeName;
                var tid = r.list[i].collegeName;
                $("#College").append("<option value='" + tid + "'>" + tname + "</option>");
            }
            loadOption('');
        }
    });

});
function query() {
    loadOption();
}
function setDate(id) {
    var Nowdate=new Date();
    M=Number(Nowdate.getMonth())+1;
    var today=Nowdate.getFullYear()+"-"+fix(M)+"-"+fix(Nowdate.getDate());
    if(id=='1'){
        $("#startDate").val(today);
        $("#endDate").val(today);
    }else if(id=='2'){
        $("#startDate").val(showWeekFirstDay());
        $("#endDate").val(today);
    }if(id=='3'){
        $("#startDate").val(showMonthFirstDay());
        $("#endDate").val(today);
    }
}
function showWeekFirstDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    M=Number(WeekFirstDay.getMonth())+1
    return WeekFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(WeekFirstDay.getDate());
}
function showWeekLastDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
    M=Number(WeekLastDay.getMonth())+1
    return WeekLastDay.getFullYear()+"-"+M+"-"+WeekLastDay.getDate();
}
function showMonthFirstDay()
{
    var Nowdate=new Date();
    var MonthFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth(),1);
    M=Number(MonthFirstDay.getMonth())+1
    return MonthFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(MonthFirstDay.getDate());
}
function fix(num){
    if(num<10)
        return "0"+num;
    else return ""+num;
}
function showMonthLastDay()
{
    var Nowdate=new Date();
    var MonthNextFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth()+1,1);
    var MonthLastDay=new Date(MonthNextFirstDay-86400000);
    M=Number(MonthLastDay.getMonth())+1
    return MonthLastDay.getFullYear()+"-"+M+"-"+MonthLastDay.getDate();
}
function getSeries(data)
{
    var     series=
    {
        name:'到课率',
        type:'bar',
        data:data,
        barWidth : 30,//柱图宽度
        markPoint: {
            data: [
                {type: 'max', name: '最大值'},
                {type: 'min', name: '最小值'}
            ]
        },
        markLine: {
            data: [
                {type: 'average', name: '平均值'}
            ]
        }
    }
    return series;
}
function loadOption(){

    $.ajax({
        url : baseURL + "/AttendenceCharts/getAttendanceProfessionRankingFirstTen",
        data : {
            "collegeName":$("#College").val(),
            "startDate":$("#startDate").val(),
            "endDate":$("#endDate").val()
        },
        dataType : "json",
        success : function(result) {

            option2.xAxis.data=result.option.classNamesFirstTen;
            option2.series=getSeries(result.option.rateFirstTen);
            studentAttendenceChartFirstTen.setOption(option2,true);

            option.xAxis.data=result.option.classNamesEndtTen;
            option.series=getSeries(result.option.rateEndTen);
            studentAttendenceChartEndTen.setOption(option,true);

        },
        error : function(errorMsg) {
            //请求失败时执行该函数
            alert("图表请求数据失败!");
            studentNonAttendenceChart.hideLoading();
        }

    })
};